package com.msconfig.mvp.view.adapter;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.geo.msconfig.R;


/*这个类是给ClientActivity中的设备Listview设配数据的
 * 
 * 
 * */

public class BlueToothDeviceAdapter extends ArrayAdapter<BluetoothDevice> {

	private LayoutInflater mInflater;
    private int mResource;
    private int mCurrentItem=0;
    private boolean mIsClick =false;

    public BlueToothDeviceAdapter(Context context, int resource) {
        super(context, resource);
        mInflater = LayoutInflater.from(context);
        mResource = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView tvName;
        RelativeLayout parentItem;
        if (convertView == null) {
            convertView = mInflater.inflate(mResource, parent, false);
        }
        tvName= (TextView) convertView.findViewById(R.id.tv_name);
        parentItem= (RelativeLayout)convertView.findViewById(R.id.parent);

        BluetoothDevice device = getItem(position);

        if(device.getName()!=null && device.getAddress()!=null){
            tvName.setText(device.getName());
        }

        parentItem.setBackgroundColor(ContextCompat.getColor(getContext(),R.color.white));
        if (mCurrentItem==position&& mIsClick){
            parentItem.setBackgroundColor(ContextCompat.getColor(getContext(),R.color.green));
        }
        return convertView;
    }

    public void setCurrentItem(int currentItem){
        this.mCurrentItem=currentItem;
    }

    public void setmIsClick(boolean mIsClick){
        this.mIsClick = mIsClick;
    }

}
